package com.gsj.boot.controller;

/**
 * @program: mybatisDriud
 * @description:
 * @author: 郭书江
 * @create: 2022-06-29 09:20
 **/
import com.gsj.boot.model.Users;
import com.gsj.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/add")
    public Users add(){
        Users users = new Users(1,"李四","男");
        userService.add("user",users);
        return users;
    }
    @GetMapping("/get")
    public Users get(){
        Users users = userService.get("user");
        return users;
    }
    @GetMapping("/del")
    public String del(){
        userService.del("user");
        return "success";
    }
    @GetMapping("/selectUsers")
    public Users selectUsers(@RequestParam String key){
        return userService.selectUsers(key);
    }
    @GetMapping("/getUsers")
    public List<Users> getUsers(@RequestParam String key,@RequestParam Long index){
        return userService.getUsers(key,index);
    }
    @GetMapping("/addList")
    public List<Users> addList(){
        List<Users> list=new ArrayList<>();
        Users users = new Users(1,"李四","男");
        Users users2 = new Users(1,"王五","男");
        list.add(users);
        list.add(users2);
        userService.addList(list);
        return list;
    }
    @GetMapping("/updateList")
    public void updateList(){
        List<Users> list=new ArrayList<>();
        Users users = new Users(1,"ccc","男");
        Users users2 = new Users(1,"maray","男");
        list.add(users);
        list.add(users2);
        userService.updateList("users2",1,list);
    }

}

